#ifndef EGG_AABB_H
#define EGG_AABB_H

#include "Base.h"

namespace egg{

    class Aabb{
    public:
        inline Aabb():mNull(true){}
        inline void add(const vec3& p){
            if(mNull){
                mNull=false;
                mMin=p,mMax=p;
            }else{
                mMin.x = min(mMin.x, p.x);
                mMin.y = min(mMin.y, p.y);
                mMin.z = min(mMin.z, p.z);
                mMax.x = max(mMax.x, p.x);
                mMax.y = max(mMax.y, p.y);
                mMax.z = max(mMax.z, p.z);
            }
        }
        inline void add(const Aabb& box){
            add(box.mMin);
            add(box.mMax);
        }
        inline void reset(){
            mNull=true;
        }
        inline vec3 getCenter() const{
            return (mMax+mMin)*vec3(0.5,0.5,0.5);
        }
        inline vec3 getLength() const{
            return vec3(getLenX(),getLenY(),getLenZ());
        }
        inline float getLenX() const{
            return mMax.x-mMin.x;
        }
        inline float getLenY() const{
            return mMax.y-mMin.y;
        }
        inline float getLenZ() const{
            return mMax.z-mMin.z;
        }
    protected:
        vec3 mMin;
        vec3 mMax;
        bool mNull;
    };

}

#endif